import { request } from '@/utils/request.util';
import type { Res, ResNull } from '@/types/common';
import type {
  PatientInfo,
  PatientQueryParams,
  RechargeOrderListData,
  RechargeOrderQueryParams,
  PatientDetail,
  PatientDetailPatientId,
  PatientRegisterListData,
  RechargeOrderListResponse
} from '@/types/patient';

/**
 * 查询患者列表
 * @param params 查询参数
 */
export const getPatientList = (params?: PatientQueryParams) =>
  request.get<Res<PatientInfo[]>>('/patient/getPatientList', { params });

/**
 * 查询患者详情
 * @param params 查询参数
 */
export const getPatientDetail = (params?: PatientDetailPatientId) =>
  request.get<Res<PatientDetail>>('/patient/getPatientDetail', { params });

/**
 * 添加患者
 * @param data 患者信息
 *
 */
export const addPatient = (data: PatientDetail) =>
  request.post<ResNull>('/patient/addPatient', data);

/**
 * 更新患者信息
 * @param data 患者信息
 *
 */
export const updatePatient = (data: PatientInfo) =>
  request.post<ResNull>('/patient/updatePatient', data);

/**
 * 患者：查询患者挂号记录
 * @param params 查询参数
 */
export const getPatientRegList = (params?: PatientDetailPatientId) =>
  request.get<Res<PatientRegisterListData>>('/clinic/register/getPatientRegList', { params });

/**
 * 患者：查询患者病历记录
 */
export const getPatientMedicalList = (params?: PatientDetailPatientId) =>
  request.get<Res<any>>('/clinic/medical/getPatientMedicalList', { params });

/**
 * 
 * 患者：查询患者随访记录
 */
export const getPatientFollowUpList = (params?: PatientDetailPatientId) =>
  request.get<Res<any>>('/clinic/followup/getPatientFollowupList', { params });

/**
 * 
 * 患者：查询患者检查/检验记录
 */

export const getPatientExamList = (params?: PatientDetailPatientId) =>
  request.get<Res<any>>('/order/exam/getPatientExamList', { params });

/**
 * 
 * 患者：查询患者执行记录
 */
export const getPatientExecList = (params?: PatientDetailPatientId) =>
  request.get<Res<any>>('/order/exec/getPatientExecList', { params });

/**
 * 
 * 患者：查询患者发药记录
 */
export const getPatientDispenseList = (params?: PatientDetailPatientId) =>
  request.get<Res<any>>('/order/dispense/getPatientDeliveryList', { params });


/**
 * 
 * 查询会员卡交易流水
 */
export const getTransList = (params?: PatientDetailPatientId) =>
  request.get<Res<any>>('/member/getTransList', {
    params,
  });

/**
 * 查询会员卡充值列表
 * @param params 查询参数
 */
export const getRechargeList = (params?: RechargeOrderQueryParams) =>
  request.get<Res<RechargeOrderListData>>('/member/getRechargeList', {
    params,
  });

  /**
   * 会员卡退款
   * 
   */
export const refundRecharge = (data: { orderId: string }) =>
  request.post<ResNull>('/member/refund', data);


/**
 * 查询患者病历字段
 */
export const getPatientMedicalField = () =>
  request.get<Res<any>>('/medical/field/getPatientMedicalFieldList?filedList=JWS,GMS');

/**
 * 会员卡充值
 */
export const recharge = (data:any) =>
  request.post<ResNull>('/member/recharge', data);